/**
 * Auto gen via dbpojo-gen.
 */
package com.us.usws.site.console.action;

import java.util.List;

import javax.inject.Inject;

import org.apache.commons.lang3.StringUtils;

import com.us.usws.model.domain.system.UserAttr;
import com.us.usws.service.cud.UserAttrCUDService;
import com.us.usws.service.ro.UserAttrROService;
import com.us.usws.support.uitls.JSONDataUtil;

/**
 * Struts2 action
 * @author robot
 */
public class UserAttrAction extends BasePageSearchAction<UserAttr> {

	private static final long serialVersionUID = 1L;

	private UserAttr userAttr;

	@Inject
	private UserAttrROService userAttrROService;

	@Inject
	private UserAttrCUDService userAttrCUDService;

	private String uids;

	/**
	 * ajax load the list of UserAttr
	 */
	public void ajaxLoadUserAttrs() {
		createDataPageUtil();
		List<UserAttr> userAttrs = userAttrROService.getUserAttrs(getStart(), getLimit());
		getOut().println(JSONDataUtil.extJsonSupportPage(userAttrs, dataPageUtil.getRowCount()));
	}

	/**
	 * ajax update UserAttr
	 */
	public void ajaxUpdateUserAttr() {
		if (userAttr != null) {
			String uid = userAttr.getUid();
			if (StringUtils.isNotBlank(uid)) {
				userAttrCUDService.updateUserAttr(userAttr);
			} else {
				userAttrCUDService.addUserAttr(userAttr);
			}
			getOut().print(true);
		} else {
			getOut().print(false);
		}
	}

	/**
	 * ajax delete user.
	 */
	public void ajaxDeleteUserAttr() {
		userAttrCUDService.deleteUserAttrMore(uids);
	}

	public void setUserAttr(UserAttr userAttr) {
		this.userAttr = userAttr;
	}

	public UserAttr getUserAttr() {
		return userAttr;
	}

	public String getUids() {
		return uids;
	}

	public void setUids(String uids) {
		this.uids = uids;
	}

}